<?php

class Weixin_payController extends Common
{
    public $member;

    public function __construct()
    {
        parent::__construct();
        $this->member = $this->model('member');
    }

    public function indexAction()
    {
        $jiage = $this->site['SITE_JIAGE'];
        $data['ordersn'] = 'SM'.time().randomkeys(2);
        $data['jine'] = $jiage;

        //微信支付
        require_once "wxpay/lib/WxPay.Api.php";
        require_once "wxpay/example/WxPay.JsApiPay.php";
        require_once 'wxpay/example/log.php';

        //初始化日志
        $logHandler= new CLogFileHandler("wxpay/logs/".date('Y-m-d').'.log');
        $log = Log::Init($logHandler, 15);

        //①、获取用户openid
        $tools = new JsApiPay();
        $openId = get_cookie('openid');

        //②、统一下单
        $input = new WxPayUnifiedOrder();
        $input->SetBody("司马招聘购买半年服务");
        $input->SetAttach("订单号：".$data['ordersn']);
        $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));//订单号
        $input->SetTotal_fee(1);//金额
//        $input->SetTotal_fee($data['jine']*100);//金额
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 600));
        $input->SetGoods_tag("司马招聘");
        $input->SetNotify_url("http://sm.my8m.com/wxpay/example/notify.php");
        $input->SetTrade_type("JSAPI");
        $input->SetOpenid($openId);
        $order = WxPayApi::unifiedOrder($input);
        $jsApiParameters = $tools->GetJsApiParameters($order);
        $this->view->assign('jsApiParameters',$jsApiParameters);
        $this->view->assign(array(
            'data'=>$data,
            'meta_title' => '选择服务',
        ));
        $this->view->display('pay');
    }

    public function pay_okAction(){
        $data['jine'] = $this->safe('jine');
        $data['ordersn'] = $this->safe('ordersn');
        $data['openid'] = get_cookie('openid');
        $data['addtime'] = time();
        $data['endtime'] = time()+3600*24*180;
        $data['status'] = 666;
//        $this->member->set('',$data);
        $this->view->assign(array(
            'data'=>$data,
        ));
        $this->view->display('pay_ok');

    }
}